<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <script src="./lib/vue.js"></script>
        <title>17 vue-filter过滤器</title>
    </head>
    <body>
        <div id="box">
            <ul>
                <li v-for="(item, index) in dataList" :key="item.id">
                    {{ item.id }} -- {{ item.name }} -- {{ item.sex | sexFilter }}
                </li>
            </ul>
        </div>

        <script>
            Vue.filter('sexFilter', (sex) => {
                let newSex = sex;
                switch (sex) {
                    case 1:
                        newSex = '女';
                        break;
                    default:
                        newSex = '男';
                        break;
                }
                return newSex;
            });

            const vm = new Vue({
                el: '#box',
                data() {
                    return {
                        dataList: [
                            { id: 1001, name: '张三', sex: 0 },
                            { id: 1002, name: '李四', sex: 1 },
                            { id: 1003, name: '王五', sex: 0 }
                        ]
                    };
                }
            });
        </script>
    </body>
</html>
